from absl import app, flags

from coin.exchange.kr_rest.feed.feed_impl import generate_feed_subscriber
from coin.exchange.util.simple_record import RecordWriter

FLAGS = flags.FLAGS

flags.DEFINE_string('exchange1', None, 'exchange name')
flags.DEFINE_string('exchange2', None, 'exchange name')
flags.DEFINE_string('product', None, 'product')


def main(_):
  feed1 = generate_feed_subscriber(
      "Spot",
      FLAGS.exchange1,
      None,  # api_version,
      FLAGS.product)
  feed2 = generate_feed_subscriber(
      "Spot",
      FLAGS.exchange2,
      None,  # api_version,
      FLAGS.product)

  while (True):
    try:
      feed1.query_book()
      feed2.query_book()
      p1 = feed1.get_best_price()
      p2 = feed2.get_best_price()
      print(p1.mid_price, p2.mid_price, p1.mid_price - p2.mid_price)
    except Exception as e:
      print("exception", e)


if __name__ == '__main__':
  app.run(main)
